package com.woniuxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.woniuxy.dto.PageDto;
import com.woniuxy.entity.Area;
import com.woniuxy.entity.Material;
import com.woniuxy.service.MaterialService;
import com.woniuxy.utils.Result;

@RestController
@RequestMapping("/material")
public class MaterialController {
	@Autowired
	private MaterialService materialService;

	@RequestMapping("/find")
	public PageDto<Material> findAllMaterial(Integer page){
		return materialService.findAllMaterial(page);
	}
	
	@RequestMapping("/add")
	public int addMaterial(Material material) {	
		return materialService.addMaterial(material);
	}
	
	@RequestMapping("/findMaterialByStatus")
	public PageDto<Material> findMaterialByStatus(Integer status,Integer page){
		return materialService.findMaterialByStatus(status, page);
	}
	
	@RequestMapping("/search")
	public PageDto<Material> searchMaterialByName(String name,Integer page){
		System.out.println(materialService.findMaterialByName(name, page));
		return materialService.findMaterialByName(name, page);	
	}
	
	@RequestMapping("/delete")
	public Result<Integer> deleteMaterialByMaid(Integer maid){
		Result<Integer> result = new Result<>();
		int res = materialService.deleteMaterialByMaid(maid);
		if (res>0) {
			return result.setMessage("删除成功~~");
		}else {
			return result.setMessage("删除失败~~");
		}	
	}
	
	@RequestMapping("/updateSwitch")
	public int updateSwitch(Integer maid, Integer value) {
		return materialService.updateSwitch(maid, value);
	}
}
